<template>
  <div>
  <div class="beijing">
    <div class="lunbotu">
      <el-carousel :interval="4000" type="card" height="450px"  style="width: 60%; margin:0 auto;">
        <el-carousel-item  v-for="item in carouselBook" :key="item.b_id">
          <img :src="item.b_cover" style="width: 100%;height: 100%">
          <span style="position: relative;top: -50px;color: turquoise;font-size: 1.5em">{{item.b_name}}</span>
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
<div>
  <div>
  <div style="display: flex; justify-content: space-between; align-items: center;">
    <el-tag type="danger" style="display: flex;">热销书籍</el-tag>
    <el-button type="text" @click="toHotBook">查看全部></el-button>
  </div>
    <el-card>
      <div style="display: flex;flex-wrap: wrap;justify-content: space-between">
        <div @click="toBookDetail(item)"  style="width: 20%;height: 280px;margin: 10px 20px;border:1px solid" v-for="item in hotBookList" :key="item.bo_number">
          <img :src="item.b_cover" style="width: 100%;height: 230px;margin-bottom: 10px">
          <div style="display: flex; justify-content: center; align-items: center;">
            <p style="margin-right: 10px;">《{{item.b_name}}》</p>
            <p style="margin-right: 10px;">{{item.bt_name}}</p>
            <span  style="background-color: transparent; padding: 5px 10px; font-weight: bold; color: #ff6347;">{{item.b_price}}元</span>
          </div>
        </div>
      </div>
    </el-card>
  </div>
  <div>
  <div style="display: flex; justify-content: space-between; align-items: center;">
    <el-tag type="success" style="display: flex;">新品书籍</el-tag>
    <el-button type="text" @click="toNewBook">查看全部></el-button>
  </div>
    <el-card>
      <div style="display: flex;flex-wrap: wrap;justify-content: space-between">
        <div @click="toBookDetail(item)" style="width: 20%;height: 280px;margin: 10px 20px;border:1px solid" v-for="item in newBookList" :key="item.b_time">
          <img :src="item.b_cover" style="width: 100%;height: 230px;margin-bottom: 10px">
          <div style="display: flex; justify-content: center; align-items: center;">
            <p style="margin-right: 10px;">《{{item.b_name}}》</p>
            <p style="margin-right: 10px;">{{item.bt_name}}</p>
            <span  style="background-color: transparent; padding: 5px 10px; font-weight: bold; color: #ff6347;">{{item.b_price}}元</span>
          </div>
           </div>
      </div>
    </el-card>
  </div>
</div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      carouselBook:[],
      hotBookList:[],
      newBookList:[],
    }
  },

  methods: {
    async getCarouselBook(){
     const { data:res} = await this.$axios.get('/book/carouselBook')
       this.carouselBook = res.data
    },
    toHotBook() {
      if (sessionStorage.getItem('u_role') === '0') {
        if (this.$route.path !== '/adminhome/hotsales') {
          this.$router.push('/adminhome/hotsales');
        }
      } else if (sessionStorage.getItem('u_role') === '1') {
        if (this.$route.path !== '/userhome/hotsales') {
          this.$router.push('/userhome/hotsales');
        }
      } else {
        if (this.$route.path !== '/home/hotsales') {
          this.$router.push('/home/hotsales');
        }
      }
    },
    toNewBook(){
      if (sessionStorage.getItem('u_role') === '0') {
        if (this.$route.path !== '/adminhome/newproducts') {
          this.$router.push('/adminhome/newproducts');
        }
      } else if (sessionStorage.getItem('u_role') === '1') {
        if (this.$route.path !== '/userhome/newproducts') {
          this.$router.push('/userhome/newproducts');
        }
      } else {
        if (this.$route.path !== '/home/newproducts') {
          this.$router.push('/home/newproducts');
        }
      }
    },
    async getHotBookList(){
      const {data:res} = await this.$axios.get('/book/hotBookList')
      console.log(res)
         this.hotBookList = res.data
    },
    async getNewBookList(){
      const {data:res} = await this.$axios.get('/book/newBookList')
      console.log(res)
          this.newBookList = res.data
    },
 toBookDetail(item){
      //跳转到书籍详情页
      let b_id = item.b_id;
      this.$router.push({path:"book_detail",query:{b_id}})

    },
  },
  mounted() {
    this.getCarouselBook();//获取书本封面轮播图
    this.getHotBookList(); //获取热销书籍列表
    this.getNewBookList(); //获取新书推荐列表
  }
}
</script>

<style>
.beijing{
  background-image: url("@/assets/beijiantu.png");
  background-size: cover; /* 使背景图覆盖整个容器 */
  background-position: center; /* 将背景图居中 */
  background-repeat: no-repeat; /* 防止背景图重复 */
  width: auto;
  height: 480px;
}
.lunbotu{
  display: flex;
}
.blank-rectangle {
  width: 400px; /* 设置宽度 */
  margin: 20px auto; /* 上下外边距和水平居中 */
  border: 1px solid #ccc; /* 设置边框样式 */
  background-color: transparent; /* 设置背景颜色 */
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 20PX;
}
.blank-rectangle-text{
  position: relative; /* 使用相对定位 */
  top: -50px;
}

.button {
  padding: 0;
  float: right;
}
.image {
  width: 100%;
  display: block;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}
.el-car ousel__item img {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #E9EEF3;
}

.el-carousel__item:nth-child(2n+1) {
  background-color: #E9EEF3;
}
</style>